{% if page_obj.has_other_pages %}
<nav aria-label="页面导航" class="mt-4">
    <ul class="pagination justify-content-center">
        {# 首页、上一页 #}
        <li class="page-item {% if not page_obj.has_previous %}disabled{% endif %}">
            {% if page_obj.has_previous %}
                <a class="page-link" href="{% url 'assets:asset_list' %}?page=1{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}" aria-label="首页">
                    <span aria-hidden="true"><i class="fas fa-angles-left"></i></span>
                </a>
            {% else %}
                <span class="page-link" aria-label="首页" aria-disabled="true" tabindex="-1"><i class="fas fa-angles-left"></i></span>
            {% endif %}
        </li>
        <li class="page-item {% if not page_obj.has_previous %}disabled{% endif %}">
            {% if page_obj.has_previous %}
                <a class="page-link" href="{% url 'assets:asset_list' %}?page={{ page_obj.previous_page_number }}{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}" aria-label="上一页">
                    <span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
                </a>
            {% else %}
                <span class="page-link" aria-label="上一页" aria-disabled="true" tabindex="-1"><i class="fas fa-angle-left"></i></span>
            {% endif %}
        </li>

        {# 页码：始终显示第一页 #}
        <li class="page-item {% if page_obj.number == 1 %}active{% endif %}">
            <a class="page-link" aria-label="第 1 页" {% if page_obj.number == 1 %}aria-current="page"{% endif %} href="{% url 'assets:asset_list' %}?page=1{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}">1</a>
        </li>

        {# 左侧省略号 #}
        {% if page_obj.number|add:'-2' > 2 %}
            <li class="page-item disabled"><span class="page-link">…</span></li>
        {% endif %}

        {# 中间窗口：当前前后2页 #}
        {% for num in page_obj.paginator.page_range %}
            {% if num >= page_obj.number|add:'-2' and num <= page_obj.number|add:'2' and num != 1 and num != page_obj.paginator.num_pages %}
                <li class="page-item {% if page_obj.number == num %}active{% endif %}">
                    <a class="page-link" aria-label="第 {{ num }} 页" {% if page_obj.number == num %}aria-current="page"{% endif %} href="{% url 'assets:asset_list' %}?page={{ num }}{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}">{{ num }}</a>
                </li>
            {% endif %}
        {% endfor %}

        {# 右侧省略号 #}
        {% if page_obj.number|add:'2' < page_obj.paginator.num_pages|add:'-1' %}
            <li class="page-item disabled"><span class="page-link">…</span></li>
        {% endif %}

        {# 最后一页（如果大于1） #}
        {% if page_obj.paginator.num_pages > 1 %}
            <li class="page-item {% if page_obj.number == page_obj.paginator.num_pages %}active{% endif %}">
                <a class="page-link" aria-label="第 {{ page_obj.paginator.num_pages }} 页" {% if page_obj.number == page_obj.paginator.num_pages %}aria-current="page"{% endif %} href="{% url 'assets:asset_list' %}?page={{ page_obj.paginator.num_pages }}{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}">{{ page_obj.paginator.num_pages }}</a>
            </li>
        {% endif %}

        {# 下一页、末页 #}
        <li class="page-item {% if not page_obj.has_next %}disabled{% endif %}">
            {% if page_obj.has_next %}
                <a class="page-link" href="{% url 'assets:asset_list' %}?page={{ page_obj.next_page_number }}{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}" aria-label="下一页">
                    <span aria-hidden="true"><i class="fas fa-angle-right"></i></span>
                </a>
            {% else %}
                <span class="page-link" aria-label="下一页" aria-disabled="true" tabindex="-1"><i class="fas fa-angle-right"></i></span>
            {% endif %}
        </li>
        <li class="page-item {% if not page_obj.has_next %}disabled{% endif %}">
            {% if page_obj.has_next %}
                <a class="page-link" href="{% url 'assets:asset_list' %}?page={{ page_obj.paginator.num_pages }}{% if search_query %}&search={{ search_query }}{% endif %}{% if request.GET.category %}&category={{ request.GET.category }}{% endif %}{% if request.GET.organization %}&organization={{ request.GET.organization }}{% endif %}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.department %}&department={{ request.GET.department }}{% endif %}{% if request.GET.user %}&user={{ request.GET.user }}{% endif %}{% if sort %}&sort={{ sort }}{% endif %}{% if order %}&order={{ order }}{% endif %}{% if per_page %}&per_page={{ per_page }}{% endif %}" aria-label="末页">
                    <span aria-hidden="true"><i class="fas fa-angles-right"></i></span>
                </a>
            {% else %}
                <span class="page-link" aria-label="末页" aria-disabled="true" tabindex="-1"><i class="fas fa-angles-right"></i></span>
            {% endif %}
        </li>
    </ul>
    <!-- 跳页输入 -->
    <div class="d-flex justify-content-center mt-2">
        <div class="input-group input-group-sm page-jump" style="max-width: 240px;">
            <span class="input-group-text">跳至</span>
            <input type="number" class="form-control" id="jumpPageInput" min="1" value="{{ page_obj.number }}" aria-label="跳至页码">
            <span class="input-group-text">页</span>
            <button class="btn btn-outline-secondary" type="button" id="jumpPageBtn">确定</button>
        </div>
    </div>
</nav>
{% endif %}
